package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.pojo.CommonResult;
import com.atguigu.springcloud.pojo.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;

/**
 * Author:   wj
 * Date:     2020/5/21 15:10
 * Description:
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

   // public static final String PAYMENT_URL = "http://localhost:8001";单机版

   public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @PostMapping("/")
    public CommonResult<Payment>   create(@RequestBody Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/",payment, CommonResult.class);
    }

    @GetMapping("/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/"+id,CommonResult.class);
    }
}
